package org.rvk.vms.service.user;

import org.rvk.vms.api.user.IUserService;
import org.rvk.vms.dal.dao.GenericDao;
import org.rvk.vms.dal.dao.UserDao;
import org.rvk.vms.dal.entities.User;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 
 * @author Ashish Kumar Sinha <aksinha.mail@gmail.com>
 *
 */
public class UserService implements IUserService {

	@Autowired
	private UserDao userDao;
	@Autowired
	private GenericDao genericDao;
	
	@Override
	public User getUser(int userId) {
		if(userId <= 0){
			throw new IllegalArgumentException("User Id is non-positive");
		}
		
		// Search in DB using User DAO
		User user = genericDao.findById(User.class, userId);
		
		// if User information is found in DB, return the User object else 
		// return null.
		
		return user;
	}

	@Override
	public User getUser(String userName) {
		return userDao.findByUsername(userName);
	}

	/**
	 * @return the userDao
	 */
	public UserDao getUserDao() {
		return userDao;
	}

	/**
	 * @param userDao the userDao to set
	 */
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	/**
	 * @return the genericDao
	 */
	public GenericDao getGenericDao() {
		return genericDao;
	}

	/**
	 * @param genericDao the genericDao to set
	 */
	public void setGenericDao(GenericDao genericDao) {
		this.genericDao = genericDao;
	}

	
}
